package bb.lanxing.net.okhttp;

import bb.lanxing.net.client.Response;
import bb.lanxing.net.core.ApiResponse;
import java.io.IOException;
import java.io.InputStream;
import okhttp3.ResponseBody;

public class OkHttpResponseWrapper implements Response, ApiResponse {
    private ResponseBody body;
    private int code;
    private boolean isSuccessful;
    private String message;

    public OkHttpResponseWrapper(okhttp3.Response response) {
        this.code = response.code();
        this.message = response.message();
        this.isSuccessful = response.isSuccessful();
        this.body = response.body();
    }

    @Override
    public int code() {
        return this.code;
    }

    @Override
    public String message() {
        return this.message;
    }

    @Override
    public boolean isSuccessful() {
        return this.isSuccessful;
    }

    @Override
    public String string() throws IOException {
        ResponseBody responseBody = this.body;
        if (responseBody != null) {
            return responseBody.string();
        }
        return null;
    }

    @Override
    public InputStream byteStream() throws IOException {
        ResponseBody responseBody = this.body;
        if (responseBody != null) {
            return responseBody.byteStream();
        }
        return null;
    }

    @Override
    public void close() throws IOException {
        ResponseBody responseBody = this.body;
        if (responseBody != null) {
            responseBody.close();
            this.body = null;
        }
    }
}
